package hibari.server.operations;

import hibari.client.model.Week;
import hibari.server.lib.AdminLog;
import hibari.server.lib.MultiPartRequest;

import javax.servlet.http.HttpServletResponse;

public class RemoveWeek extends PMOperation {

    public RemoveWeek(MultiPartRequest request, HttpServletResponse response) {
        super(request, response);
    }

    @Override
    public void doOperation() {
        try {
            Week week = getPM().getObjectById(Week.class, Long.parseLong(getRequest().getParameter("id")));
            week.setAlive(false);
            getPM().makePersistent(week);
            getPM().close();
            AdminLog.get(getRequest()).addInfo("Week #" + week.getWeekNumber() + " was been moved into <a href=\"/Admin/RemovedWeekList.jsp\">trash bin</a>.");
        } catch (Exception e) {
            AdminLog.get(getRequest()).addError(e.getMessage());
        }
    }

}
